package com.example.javaee.common;
import lombok.Data;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Data
    public class result<T> {
        private Integer code; //编码：1成功，0和其它数字为失败
        private String msg; //错误信息
        private T data; //数据
        private Map map = new HashMap(); //动态数据
        public static <T> result<T> success(T object,String ms) {
            result<T> r = new result<T>();
            r.data = object;
            r.code = 1;
            r.msg = ms;
            return r;
        }
        public static <T> result<T> error(String msg) {
            result r = new result();
            r.msg = msg;
            r.code = 0;
            return r;
        }
        public result<T> add(String key, Object value) {
            this.map.put(key, value);
            return this;
        }
}
